package com.um.jdy.common.device.service.impl;

import cn.hutool.core.date.DateUtil;
import com.um.jdy.common.device.enums.DeviceEnum;

import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import com.um.springboot.starter.orm.service.BaseEntityServiceImpl;
import com.um.jdy.common.device.service.OnlineLogService;
import com.um.jdy.common.device.dao.OnlineLogDao;
import com.um.jdy.common.device.entity.po.OnlineLog;

/**
 * 服务实现类：设备上线离线日志
 */
@Service
@Slf4j
public class OnlineLogServiceImpl extends BaseEntityServiceImpl<OnlineLogDao,OnlineLog>  implements OnlineLogService{

    /**
     * 设备上线
     *
     * @param code
     * @param deviceName
     */
    @Override
    public void addOnline(String code, String deviceName) {
        OnlineLog record = new OnlineLog();
        record.setCode(code);
        record.setDeviceName(deviceName);
        record.setType(DeviceEnum.DeviceStatus.Online.name());
        record.setCreateTime(DateUtil.date());
        this.saveRow(record);
    }

    /**
     * 设备下线
     *
     * @param code
     * @param deviceName
     */
    @Override
    public void addOffline(String code, String deviceName) {
        OnlineLog record = new OnlineLog();
        record.setCode(code);
        record.setDeviceName(deviceName);
        record.setType(DeviceEnum.DeviceStatus.Offline.name());
        record.setCreateTime(DateUtil.date());
        this.saveRow(record);
    }
}
